package com.gxa.p2p.service.impl;

import com.gxa.p2p.mapper.AccountInfoMapper;
import com.gxa.p2p.mapper.MultiAddrMapper;
import com.gxa.p2p.mapper.UserInfoMapper;
import com.gxa.p2p.pojo.AccountInfo;
import com.gxa.p2p.pojo.UserInfo;
import com.gxa.p2p.service.AccountInfoService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;

@Service
@Transactional
public class AccountInfoServiceImpl implements AccountInfoService {

    // 获取
    @Resource
    AccountInfoMapper accountInfoMapper;
    @Resource
    UserInfoMapper userInfoMapper;
    @Resource
    MultiAddrMapper multiAddrMapper;
    @Override
    public HashMap<String, Object> findById(Integer userId) {
        HashMap<String, Object> ObjectMap = new HashMap<>();
        AccountInfo accountInfo = accountInfoMapper.selectByUserId(userId);
        UserInfo userInfo = userInfoMapper.selectByUserId(userId);
        if(userInfo != null && !"".equals(userInfo.getAvatar())){
            // 如果对象不为空且头像不为空,对图片地址进行拼接
            userInfo.setAvatar(multiAddrMapper.selectImgAddr().getAddress()+userInfo.getAvatar());
        }
        // 返回整个对象给前端，或者返回带有实名认证信息/手机号/邮箱的一个map
        ObjectMap.put("userInfo",userInfo);
        ObjectMap.put("accountInfo",accountInfo);
        return ObjectMap;
    }

    @Override
    public Boolean UpAcc(AccountInfo accountInfo) {
        return  accountInfoMapper.updateByPrimaryKeySelective(accountInfo)>0;
    }

}
